package com.xvxingan.dataapi.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.xvxingan.base.controller.BaseController;
import com.xvxingan.mvc.mq.service.TestService;
import com.xvxingan.utils.DateUtil;

import sun.misc.BASE64Encoder;

@Controller
public class TestController extends BaseController {
	
	@Autowired
	private TestService service;
	/**
	 * 测试模拟使用
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("/feedback_test")
	public ModelAndView testFeedBack(HttpServletRequest request) {
		String content = request.getParameter("content");
		System.out.println("-------------反馈接口测试-----------------");
		System.out.println(content);
		return new ModelAndView(new MappingJacksonJsonView(), null);
	}

	@RequestMapping(value = "/zhongliang.htm",method=RequestMethod.POST)
	public String zhongliang() {
		return "forward:/resources/zhongliang.xml";
	}
	@RequestMapping(value = "/zhongliangreturn.htm", method=RequestMethod.POST)
	public String zhongliangreturn() {
		return "forward:/resources/zhongliangreturn.xml";
	}

	@RequestMapping(value = "/yihaodian.htm",method=RequestMethod.POST)
	public String yihaodian(HttpServletResponse resp) {
		return "forward:/resources/yihaodian.xml";
	}

	@RequestMapping(value = "/yihaodianreturn.htm",method=RequestMethod.POST)
	public String yihaodianreturn(HttpServletResponse resp) {
		return "forward:/resources/yihaodianreturn.xml";
	}
	
	@RequestMapping("/yace.htm")
	@ResponseBody
	public String yace(HttpServletRequest req) throws Exception{
		long i = new Date().getTime();
		long num = 100;
		if(StringUtils.isNotBlank(req.getParameter("num")))num = Long.valueOf(req.getParameter("num"));
  		long len = num + i;
		while(i<len){
			i++;
			this.service.producer.sendBody(i);
		}
		return "ok";
		
	}
	@Test
	public void test(){
		String s = (new BASE64Encoder()).encodeBuffer("abcd".getBytes());              
		String s2 = Base64.encodeBase64String("abcd".getBytes());
		System.out.println(s);
		System.out.println(s2);
		System.out.println(new String(Base64.decodeBase64(s2)));;
	}
}
